//
//  MusicView.m
//  aMoment
//
//  Created by dllo on 15/10/1.
//  Copyright © 2015年 LuckyHan. All rights reserved.
//

#import "MusicView.h"
#import "AllHeaderFiles.h"

@implementation MusicView

- (void)dealloc
{
    [_coverImageView release];
    [_songNameLabel release];
    [_singerLabel release];
    [_playImageView release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createViews];
    }
    return self;
}

- (void)createViews
{
    _coverImageView = [[UIImageView alloc] init];
    _coverImageView.image = [UIImage imageNamed:@"placeholder-cd"];
    [self addSubview:_coverImageView];
    
    _songNameLabel = [[UILabel alloc] init];
    _songNameLabel.textColor = [UIColor whiteColor];
    [self addSubview:_songNameLabel];
    
    _singerLabel = [[UILabel alloc] init];
    _singerLabel.textColor = [UIColor whiteColor];
    _singerLabel.font = [UIFont systemFontOfSize:FONTSIZE_SMALL];
    [self addSubview:_singerLabel];
    
    _playImageView = [[UIImageView alloc] init];
    _playImageView.image = [UIImage imageNamed:@"iconfont-menuplay"];
    _playImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickPlayImageViewAction:)];
    [_playImageView addGestureRecognizer:tap];
    [self addSubview:_playImageView];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _coverImageView.frame = CGRectMake(10 * FIT_HEIGHT, 10 * FIT_HEIGHT, self.Height - 20 * FIT_HEIGHT, self.Height - 20 * FIT_HEIGHT);
    _songNameLabel.frame = CGRectMake(_coverImageView.X + _coverImageView.Width + 5 * FIT_WIDTH, _coverImageView.Y, 155 * FIT_WIDTH, _coverImageView.Height / 2);
    _singerLabel.frame = CGRectMake(_songNameLabel.X, _songNameLabel.Y + _songNameLabel.Height, _songNameLabel.Width, _songNameLabel.Height);
    _playImageView.frame = CGRectMake(_songNameLabel.X + _songNameLabel.Width + 15 * FIT_WIDTH, _coverImageView.center.y - 12 * FIT_WIDTH, 24 * FIT_WIDTH, 24 * FIT_WIDTH);
}

#pragma mark 点击播放按钮方法
- (void)clickPlayImageViewAction:(UITapGestureRecognizer *)tap
{
    if (_musicURL) {
        [[MusicSingleton shareInstance] playMusicWith:_musicURL];
        if (!_flag) {
            _playImageView.image = [UIImage imageNamed:@"iconfont-menuplay"];
            _flag = 1;
        } else {
            _playImageView.image = [UIImage imageNamed:@"iconfont-menustop"];
            _flag = 0;
        }
        NSLog(@"%@", _musicURL);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
